<?php
/**
 * Created by PhpStorm.
 * User: zhangtao
 * Date: 16-5-19
 * Time: 下午4:20
 */

namespace Home\Controller;


use Think\Controller;

class UserController extends Controller
{
    public function index()
    {
    }
    public function signup()
    {
        $user = M('User');
        if ($user->field('username,password')->create()) {
            if ($user->where(array('username' => I("post.username")))->find()) {
                $this->ajaxReturn(array('status' => 'fail'));
            } else {
                $user->add();
                $this->ajaxReturn(array('status' => 'success'));
            }
        }
    }

    public function signin()
    {
        $user = M('User');
        $map['username'] = I('post.username');
        $map['password'] = I('post.password');
        if ($user->where($map)->find()) {
            session('username', $map['username']);
            $this->ajaxReturn(array('status' => 'success'));
        }
        else
            $this->ajaxReturn(array('status' => 'fail'));
    }

}